package com.acme.bankapp.domain.bank;


public abstract class AbstractAccount implements Account{

	// protected final int id;
	protected double balance;

	public AbstractAccount(){}
	public AbstractAccount( double amount) throws IllegalArgumentException{
		if(amount < 0){
			throw new IllegalArgumentException();
		}else{
			this.balance = amount;
		}
	}

	public double getBalance() {
		return this.balance;
	}
	
	
	
	public int decimalValue(){
		return (int) Math.round(this.balance);
	}

	
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		long temp = Long.valueOf(Double.doubleToLongBits(balance)).hashCode(); //I can get hashCode from Long, but inside it the same sh*t [(int)(value ^ (value >>> 32));]
		result = prime * result + (int) temp;
		return result;
	}

	
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		AbstractAccount other = (AbstractAccount) obj;
		if (Double.doubleToLongBits(balance) != Double
				.doubleToLongBits(other.balance))
			return false;
		return true;
	}

	
	public String toString() {
		return "AbstractAccount [balance=" + balance + ", hashCode()="
				+ hashCode() + "]";
	}
	
	
	

}
